<?php
class Users_model extends CI_Model {

	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    //TODO: fix this
	function add_new_user()
	{
		/*
		 *  save the user added by user to database
		 *  
		 * */
		date_default_timezone_set('America/New_York');
		$created_date = date("Y-m-d");
		
		$data = array(
					'name' => $this->input->post('institution_name'),
					'created_date' => $created_date,
					'updated_date' => $created_date,
					'created_by' => $this->session->userdata('username'),
					'updated_by' => $this->session->userdata('username'),
					'deprecated' => 'N',
				);
		
		$this->db->insert('vm_users',$data);
	}
	
	function view_all_users(){
		/*
		 *  construct a list of user data and send back to controller
		 * */
		$this->db->select('vm_users.user_id, vm_institutions.name, vm_users.username, vm_users.created_date, 
			vm_users.created_by, vm_users.is_super_admin, vm_users.deprecated')->from('vm_users');
		$this->db->join('vm_institutions', 'vm_users.institution_id = vm_institutions.institution_id');

		$results_array = $this->db->get();
		
		return $results_array;
		
	}

}
?>